#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
class Solution
{
public:
    bool digitCount(string num)
    {
        unordered_map<char, int> ans;
        for (int n : num)
        {
            ans[n - '0']++;
        }

        for (int i = 0; i < num.size(); i++)
        {
            cout << num[i] << ":" << ans[i] << endl;
            if (num[i] - '0' != ans[i])
            {
                return false;
            }
        }
        return true;
    }

    bool digitCount_2(string num)
    {
        for (int i = 0; i < num.size(); i++)
        {
            char a = num[i];
            int k = 0; //计数器
            for (int j = 0; j < num.size(); j++)
            {
                if (i == num[j] - '0')
                    k++;
            }
            if (k != num[i] - '0')
                return false;
        }
        return true;
    }
};
int main()
{
    Solution s;
    cout << s.digitCount("1210") << endl;
    system("pause");
    return 0;
}
